<?php

class Sms_queue extends CActiveRecord
{
	/**
	 * The followings are the available columns in table 'Sms_queue':
	 * @var integer $id
	 * @var string $mobile_no
	 * @var string $msg
	 * @var string $send_user
	 * @var integer $state
	 * @var integer $sent
	 * @var string $send_time
	 * @var string $craete_time
	 */
	
	public $driver_id;
	private $_sent=array(0=>'否',1=>'是');
	
	/**
	 * Returns the static model of the specified AR class.
	 * @return CActiveRecord the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'sms_queue';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		return array(
			array('msg','length','max'=>70),
			array('msg', 'required'),
		);
	}
	
	/**
	 * Prepares attributes before performing validation.
	 */
	protected function beforeValidate($on)
	{
		if($this->isNewRecord){
			$this->state=0;
			$this->create_time=date('Y-m-d G:i:s');
			$this->send_user=Yii::app()->session['username'];
			$this->send_user_name=Yii::app()->session['true_name'];
		}
		return true;
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => '主键',
			'receiver_name'=>'收信人姓名',
			'mobile_no' => '手机号',
			'msg' => '发送内容',
			'send_user' => '发送用户名',
			'send_user_name' => '发送用户姓名',
			'state' => '状态',
			'sent' => '已发送',
			'send_time' => '发送时间',
			'create_time' => '添加时间',
		);
	}
	
	public function getSentName($n=null){
		return $this->_sent[$n==null?$this->sent:$n];
	}
	
	public function safeAttributes(){
		$params=parent::safeAttributes();
		$params[]='driver_id';
		return $params;
	}
}